cssmatcher: Marshal name to matcher
authorBenjamin Otte <otte@redhat.com>
Sat, 5 Sep 2015 04:39:10 +0000 (06:39 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 22 Oct 2015 14:35:14 +0000 (16:35 +0200)
... and use it in the node matcher.

Also rename function from _gtk_css_matcher_get_type() to
_gtk_css_matcher_get_name().

gtk/gtkcssmatcher.c
gtk/gtkcssmatcherprivate.h
gtk/gtkcssselector.c

index d371bd87ece4e8c6bc94e62a2dbfbfaa54e98071..cb9f7338d8b8c055bdc14a7c32c03738c8ac307e 100644 (file)
@@ -73,11 +73,15 @@ gtk_css_matcher_widget_path_get_state (const GtkCssMatcher *matcher)
 }
 
 static gboolean
-gtk_css_matcher_widget_path_has_type (const GtkCssMatcher *matcher,
-                                      GType                type)
+gtk_css_matcher_widget_path_has_name (const GtkCssMatcher     *matcher,
+                                      /*interned*/ const char *name,
+                                      GType                    type)
 {
   const GtkWidgetPath *siblings;
 
+  if (type == 0)
+    return FALSE;
+
   siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
   if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
     return g_type_is_a (gtk_widget_path_iter_get_object_type (siblings, matcher->path.sibling_index), type);
@@ -215,7 +219,7 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
   gtk_css_matcher_widget_path_get_parent,
   gtk_css_matcher_widget_path_get_previous,
   gtk_css_matcher_widget_path_get_state,
-  gtk_css_matcher_widget_path_has_type,
+  gtk_css_matcher_widget_path_has_name,
   gtk_css_matcher_widget_path_has_class,
   gtk_css_matcher_widget_path_has_id,
   gtk_css_matcher_widget_path_has_regions,
@@ -296,10 +300,16 @@ gtk_css_matcher_node_get_state (const GtkCssMatcher *matcher)
 }
 
 static gboolean
-gtk_css_matcher_node_has_type (const GtkCssMatcher *matcher,
-                               GType                type)
+gtk_css_matcher_node_has_name (const GtkCssMatcher     *matcher,
+                               /*interned*/ const char *name,
+                               GType                    type)
 {
-  return g_type_is_a (gtk_css_node_get_widget_type (matcher->node.node), type);
+  const char *node_name = gtk_css_node_get_name (matcher->node.node);
+
+  if (node_name == NULL)
+    return g_type_is_a (gtk_css_node_get_widget_type (matcher->node.node), type);
+  
+  return node_name == name;
 }
 
 static gboolean
@@ -401,7 +411,7 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_NODE = {
   gtk_css_matcher_node_get_parent,
   gtk_css_matcher_node_get_previous,
   gtk_css_matcher_node_get_state,
-  gtk_css_matcher_node_has_type,
+  gtk_css_matcher_node_has_name,
   gtk_css_matcher_node_has_class,
   gtk_css_matcher_node_has_id,
   gtk_css_matcher_node_has_regions,
@@ -450,8 +460,9 @@ gtk_css_matcher_any_get_state (const GtkCssMatcher *matcher)
 }
 
 static gboolean
-gtk_css_matcher_any_has_type (const GtkCssMatcher *matcher,
-                              GType                type)
+gtk_css_matcher_any_has_name (const GtkCssMatcher     *matcher,
+                              /*interned*/ const char *name,
+                              GType                    type)
 {
   return TRUE;
 }
@@ -497,7 +508,7 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_ANY = {
   gtk_css_matcher_any_get_parent,
   gtk_css_matcher_any_get_previous,
   gtk_css_matcher_any_get_state,
-  gtk_css_matcher_any_has_type,
+  gtk_css_matcher_any_has_name,
   gtk_css_matcher_any_has_class,
   gtk_css_matcher_any_has_id,
   gtk_css_matcher_any_has_regions,
@@ -547,11 +558,12 @@ gtk_css_matcher_superset_get_state (const GtkCssMatcher *matcher)
 }
 
 static gboolean
-gtk_css_matcher_superset_has_type (const GtkCssMatcher *matcher,
-                                   GType                type)
+gtk_css_matcher_superset_has_name (const GtkCssMatcher     *matcher,
+                                   /*interned*/ const char *name,
+                                   GType                    type)
 {
   if (matcher->superset.relevant & GTK_CSS_CHANGE_NAME)
-    return _gtk_css_matcher_has_type (matcher->superset.subset, type);
+    return _gtk_css_matcher_has_name (matcher->superset.subset, name, type);
   else
     return TRUE;
 }
@@ -617,7 +629,7 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_SUPERSET = {
   gtk_css_matcher_superset_get_parent,
   gtk_css_matcher_superset_get_previous,
   gtk_css_matcher_superset_get_state,
-  gtk_css_matcher_superset_has_type,
+  gtk_css_matcher_superset_has_name,
   gtk_css_matcher_superset_has_class,
   gtk_css_matcher_superset_has_id,
   gtk_css_matcher_superset_has_regions,
index 1a788f3565f5b56dc25d5e5d4bb3cc97af44cd1a..dce57b28a8454a7639587b4880a4b1a7d7dfafcb 100644 (file)
@@ -36,7 +36,8 @@ struct _GtkCssMatcherClass {
                                                    const GtkCssMatcher    *next);
 
   GtkStateFlags   (* get_state)                   (const GtkCssMatcher   *matcher);
-  gboolean        (* has_type)                    (const GtkCssMatcher   *matcher,
+  gboolean        (* has_name)                    (const GtkCssMatcher   *matcher,
+                                                   /*interned*/const char*name,
                                                    GType                  type);
   gboolean        (* has_class)                   (const GtkCssMatcher   *matcher,
                                                    GQuark                 class_name);
@@ -111,10 +112,11 @@ _gtk_css_matcher_get_state (const GtkCssMatcher *matcher)
 }
 
 static inline gboolean
-_gtk_css_matcher_has_type (const GtkCssMatcher *matcher,
-                           GType type)
+_gtk_css_matcher_has_name (const GtkCssMatcher     *matcher,
+                           /*interned*/ const char *name,
+                           GType                    type)
 {
-  return matcher->klass->has_type (matcher, type);
+  return matcher->klass->has_name (matcher, name, type);
 }
 
 static inline gboolean
index e987aa1292248289577fbc244086c9f29c8026a2..ea4f252529528102f43fdd769484e886afc3e87f 100644 (file)
@@ -690,7 +690,7 @@ static gboolean
 match_name (const GtkCssSelector *selector,
             const GtkCssMatcher  *matcher)
 {
-  return _gtk_css_matcher_has_type (matcher, selector->name.reference->type);
+  return _gtk_css_matcher_has_name (matcher, selector->name.reference->name, selector->name.reference->type);
 }
 
 static guint